<!DOCTYPE html>
<html lang="zh-cmn-Hans">
  <head>
    <meta charset="utf-8"/>
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
    <title>車間機台設備異常公布</title>
	<!-- 引入LayUI的样式文件 -->
	<link rel="stylesheet" href="../layui/css/layui.css"/>
  </head>
	<body>
		<div class="layui-row">
			<div class="layui-col-sm4">
				<input class="form-control" placeholder="筛选工序"  id="Fruit" type="text"/>
				<label><input name="Fruit" type="checkbox" value="齐纳" />齐纳 </label> 
				<label><input name="Fruit" type="checkbox" value="固晶" />固晶 </label> 
				<label><input name="Fruit" type="checkbox" value="焊线" />焊线 </label> 
				<label><input name="Fruit" type="checkbox" value="点胶" />点胶 </label> 
				<label><input name="Fruit" type="checkbox" value="切割" />切割 </label> 
				<label><input name="Fruit" type="checkbox" value="分光" />分光 </label> 
				<label><input name="Fruit" type="checkbox" value="编带" />编带 </label> 
			</div>
			<div class="layui-col-sm4">
				<input class="form-control" placeholder="筛选停機時長"  id="Stop" type="text"/>
				<label><input name="Stop" type="checkbox" value="0~1" />0~1 </label> 
				<label><input name="Stop" type="checkbox" value="1~2" />1~2 </label> 
				<label><input name="Stop" type="checkbox" value="2~3" />2~3 </label> 
				<label><input name="Stop" type="checkbox" value=">3" />>3 </label> 
			</div>
		</div>	
		<fieldset class="layui-elem-field site-demo-button">
			<legend><big><b>异常停机</b></big></legend>
			<div class="layui-fluid layui-form layui-form-pane">
				<div id="YC" class="layui-row"></div>
			</div>
		</fieldset>
		<script src="../_vendor/jquery/dist/jquery.min.js"></script>
		<!-- 载入layui模块脚本 -->
		<script src="../layui/layui.js"></script>
		<script>
			layui.use(['layer','form','element'], function(){
				layer.msg('画面载入成功!');
			});
			var YC = {
				 "EXC01":"首件"
				,"EXC02":"生产调机"
				,"EXC03":"更换耗材"
				,"EXC04":"日点检保养"
				,"EXC05":"冶具清理"
				,"EXC06":"工单切换调机"
				,"EXC11":"设备故障调机"
				,"EXC21":"其他计划外停机"
				,"EXC22":"待机"
			}
			var YCYY = {
				 "EXC01":"手贱"
				,"EXC02":"生产条机"
				,"EXC03":"更换耗材"
				,"EXC04":"日点检保养"
				,"EXC05":"冶具清理"
				,"EXC06":"工单切换条机"
				,"EXC11":"设备故障条机"
				,"EXC21":"其他计划外停机"
				,"EXC22":"待机"
				/*,"首件":"手贱"
				,"生产调机":"生产条机"
				,"更换耗材":"更换耗材"
				,"日点检保养":"日点检保养"
				,"冶具清理":"冶具清理"
				,"工单切换调机":"工单切换条机"
				,"设备故障调机":"设备故障条机"
				,"其他计划外停机":"其他计划外停机"*/
			}
			var BP = {
				 "BPA":"固晶"
				,"BPC":"焊线"
				,"BPD":"点胶"
				,"BPG":"切割"
				,"BPI":"分光"
				,"BPJ":"编带"
			}
			var CLASS = {
				 "B":"layui-bg-blue"
				,"C":"layui-bg-cyan"
				,"G":"layui-bg-gray"
				,"Y":"layui-bg-green"
			}
			var JT = "";
			var JT2 = {};
			var DQYC = {};
			var YCT = {};
			$("input[name^='Fruit']").on('click',function(){//监听复选框
			var keys="Fruit";
			fun(keys);
			});
			$("input[name^='Exception_type']").on('click',function(){
			var keys="Exception_type";
			fun(keys);
			});
			$("input[name^='Stop']").on('click',function(){
			var keys="Stop";
			fun(keys);
			});
			function fun(keys){//获取复选框的值
				obj = document.getElementsByName(keys);
				check_val = [];
				for(k in obj){
					if(obj[k].checked)
						check_val.push(obj[k].value);
						$("#"+keys).val(check_val);
				}
				//alert(check_val);
			}
			$(document).ready(function(){
				setInterval(function (){
					//var tempHtml = "";
					//$('#excp').html("");
					$.ajax({ url: "getExcp.php", //
							dataType : "json",
							success: function(sss){
								layer.msg('查询成功');//,返回信息
								if(sss['EXC'].length>0){
									layer.msg('00');
									for (var i=0;i<sss['EXC'].length;i++){
										layer.msg('01');
										if(sss['EXC'][i]['异常机台'] !== undefined){
											layer.msg('0');
											//这里优化代码
											if(JT2[sss['EXC'][i]['异常机台']] > 0){
												layer.msg('1');
												if(sss['EXC'][i]['开始结束'] === '当前状态'){
													layer.msg('2');
													//用jQuery选择器选择当前机台的位置,然后向前插入文本
													$("#" + sss['EXC'][i]['异常机台'] + " div.layui-field-box:first").prepend(
														"<div>"+
															"<br/>机台状态: " + YC[sss['EXC'][i]['异常码']] +
															"丨"+ sss['EXC'][i]['开始结束'] +": "+ sss['EXC'][i]['时间'] +
														"</div>"
													);
													//这里把特定的字典也一并处理
													YCT[sss['EXC'][i]['异常机台']] = sss['EXC'][i]['时间'];//机台异常时间
													JT2[sss['EXC'][i]['异常机台']] = 1;//机台字典里面的值=1
													DQYC[sss['EXC'][i]['异常机台']] = sss['EXC'][i]['异常码'];//当前机台的异常状态
													$("#"+sss['EXC'][i]['异常机台']+"d").prependTo("#YC");//并移动到前面去
												}else{
													layer.msg('3');
													//用jQuery选择器选择当前机台的位置,然后向前插入文本
													$("#" + sss['EXC'][i]['异常机台'] + " div.layui-field-box:first").prepend(
														"<div>"+
															"<br/>机台状态: " + YC[sss['EXC'][i]['异常码']] +
															"丨"+ sss['EXC'][i]['开始结束'] +": "+ sss['EXC'][i]['时间'] +
														"</div>"
													);
													//这里把特定的字典也一并处理
													JT2[sss['EXC'][i]['异常机台']] += 1;//机台字典里面的值+1
													DQYC[sss['EXC'][i]['异常机台']] = "";//写完之后,当前机台的异常就没有了
												}
											}else{
												layer.msg('4');
												$("#YC").append(
													"<div id='" + sss['EXC'][i]['异常机台'] + "d' class='layui-col-xs6 layui-col-sm4 layui-col-md4 layui-anim-up'>"+
														"<fieldset id='" + sss['EXC'][i]['异常机台'] + "' class='layui-elem-field layui-form layui-form-pane'>"+
															"<legend>机台号: " + sss['EXC'][i]['异常机台'] + "</legend>"+
															"<div class='layui-field-box'>"+
																"<div>"+
																	"<br/>机台状态: " + YC[sss['EXC'][i]['异常码']] +
																	"丨"+ sss['EXC'][i]['开始结束'] +": "+ sss['EXC'][i]['时间'] +
																"</div>"+
															"</div>"+
														"</fieldset>"+
													"</div>"
												);
												if(sss['EXC'][i]['开始结束'] === '当前状态'){
													$("#"+sss['EXC'][i]['异常机台']+"d").prependTo("#YC");//并移动到前面去
													YCT[sss['EXC'][i]['异常机台']] = sss['EXC'][i]['时间'];//机台异常时间
												}
												//这里把特定的字典也一并处理
												JT2[sss['EXC'][i]['异常机台']] = 1;//机台字典里面的值=1
												DQYC[sss['EXC'][i]['异常机台']] = sss['EXC'][i]['异常码'];//当前机台的异常状态
											}
										}
									}
									//这里是JavaScript语音合成的模块
									JT = sss[0]["异常机台"];
									//设置YY是新建的语音合成对象
									var YY = new window.SpeechSynthesisUtterance();
									//设置语音合成对象的文本
									YY.text ='';
									YY.text = 
										'机台号：' + BP[JT.substr(0,3)] +'G'+ JT.substr(3,JT.length-3) +
										'，机台状态：' + sss[0]["异常现象"] +  '。'
									;
									//设置语音合成的语言
									YY.lang = "zh-cmn-Hans";
									//设置语音合成的语速
									YY.rate = 1.2;
									//用这个方法让YY实体化(说出来)
									window.speechSynthesis.speak(YY);
								}
							}
						});    
				},10000);
			});
		</script>
	</body>
</html>